<?php    
    if (!defined('EXPONENT')) exit('');
     if (exponent_users_isAdmin() ||  exponent_permissions_check(array("administrate"),$loc)){
        $sql_where = '1 ';
        if(isset($_REQUEST['search_name']))
        {   
            $search_name = ($_REQUEST['search_name']);
            $sql_where.=" AND ((firstname LIKE '%{$search_name}%') OR (lastname LIKE '%{$search_name}%'))";
        }
        $page=1;
            if (isset($_REQUEST['page']))
            $page=intval($_REQUEST['page']);
        $pageSize=10;
        
        if (isset($_REQUEST['rows']))
            $pageSize=intval($_REQUEST['rows']);
        $start=($page-1)*$pageSize;
        
        // sort
        $sort="";
        if (isset($_REQUEST['sortName'])){
            $sort = " ORDER BY {$_REQUEST['sortName']} {$_REQUEST['sortOrder']}";
        }
        
        $data=$db->selectObjects('user',"{$sql_where} {$sort} LIMIT {$start},{$pageSize}");
        foreach ($data as $k=>$v){
            // split description
            $v->created_on = date('d/m/Y H:i:s',$v->created_on);
            if($v->last_login>0)
            $v->last_login = date('d/m/Y H:i:s',$v->last_login);
            else
            $v->last_login='';
        }
        $ret_object = null;
        $ret_object->total = $db->countObjects('user',"{$sql_where}");
        $ret_object->rows = $data; 
        echo json_encode($ret_object);
    }
    die();
?>